package com.workcell.workdata.xthings.service.impl;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Dict;
import com.workcell.workdata.common.core.util.R;
import com.workcell.workdata.common.security.util.SecurityUtils;
import com.workcell.workdata.xthings.api.feign.RemoteFormDataService;
import com.workcell.workdata.xthings.dto.fd.FormTableDTO;
import com.workcell.workdata.xthings.dto.fd.QueryField;
import com.workcell.workdata.xthings.dto.fd.SavaCommentVo;
import com.workcell.workdata.xthings.service.XiaoSiMapService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service
public class XiaoSiMapServiceImpl implements XiaoSiMapService {
    @Resource
    private RemoteFormDataService remoteFormDataService;

    @Override
    public void saveComment(SavaCommentVo savaCommentVo) {
        Dict dict = Dict.create()
                .set("templateId", "1688502914937815040")
                // 异常申报ID
                .set("a16916377939816523", savaCommentVo.getId())
                // 用户名
                .set("a169163776937480483", SecurityUtils.getUser().getName())
                // 评论内容
                .set("a16916377939816523", savaCommentVo.getContent())
                // 评论时间
                .set("a169163781766580837", LocalDateTime.now());
        remoteFormDataService.formInstanceSave(dict);
    }

    @Override
    public R commentList(String id, Integer current, Integer size) {
        QueryField queryField = QueryField.builder()
                // 异常申报id
                .fieldName("a16916377939816523")
                .fieldValue(id)
                .build();

        FormTableDTO formTableDTO = FormTableDTO.builder()
                .templateId(1688502914937815040L)
                .queryFieldList(ListUtil.of(queryField))
                .build();
        formTableDTO.setCurrent(current);
        formTableDTO.setSize(size);
        return remoteFormDataService.formInstancePage(formTableDTO);
    }
}
